// ignore_for_file: invalid_use_of_protected_member
import 'package:get/get.dart';
import 'package:flutter/material.dart';

import 'home_controller.dart';
import 'widgets/home_appbar.dart';
import 'widgets/home_drawer.dart';
import 'widgets/home_main_list.dart';
import 'widgets/home_search_list.dart';

class HomePage extends GetView<HomeController> {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: HomeAppBar(
        title: const Text("密码管理"),
        onToggle: (isSearching) {
          controller.searchList.value = [];
          controller.isSearching.value = isSearching;
        },
        onSearch: (query) => controller.searchQuery.value = query,
      ),
      drawer: const HomeDrawer(),
      body: Scrollbar(
        child: SingleChildScrollView(
          child: Obx(
            () => controller.isSearching.value
                ? HomeSearchList(searchList: controller.searchList.value)
                : HomeMainList(mainList: controller.mainList.value),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        heroTag: "addPassword",
        onPressed: () async {
          await Get.toNamed("/pass?mode=add");
          controller.refreshMainList();
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
